package cn.northsea.entity;

import com.alibaba.fastjson.JSON;
import lombok.Data;

import java.io.IOException;


@Data
public class PrivateChatMessage {

    private String fromUser;
    private String toUser;
    private String message;
    //已读状态 0:否,1:是
    private Integer status;
    //发送时间
    private Long timestamp;

    public PrivateChatMessage(String fromUser, String toUser, String message) {
        this.fromUser = fromUser;
        this.toUser = toUser;
        this.message = message;
        this.status = 0;
        this.timestamp = System.currentTimeMillis();
    }

    @Override
    public String toString() {
        return "PrivateChatMessage{" +
                "fromUser='" + fromUser + '\'' +
                ", toUser='" + toUser + '\'' +
                ", message='" + message + '\'' +
                ", status=" + status +
                ", timestamp=" + timestamp +
                '}';
    }

    //序列化
    public String toJson() throws IOException {
        return JSON.toJSONString(this);
    }

    //反序列化
    public static PrivateChatMessage fromJson(String json) throws IOException {
        return JSON.parseObject(json,PrivateChatMessage.class);
    }
}
